package game;

import java.io.IOException;

/**
 *@author Gary Doyle
 * 
 *Class for testing game implementation. Not representative of final project, used mainly for emulating game flow and win conditions. 
 */
public class Game {
    
	public static int roundNo,pot;
       
    public static void main (String[] args) throws IOException{
 


        //make agents
        ComputerAgent ca = new ComputerAgent(20, 50, 50, 1);
        ComputerAgent ca1 = new ComputerAgent(20, 50, 50, 2);
        ComputerAgent ca2 = new ComputerAgent(20, 5, 50, 3);
        PlayerAgent pa = new PlayerAgent(20);
        
       
        
               
        while(!pa.isBankrupt()||!ca.isBankrupt()){
       
        	 System.out.println("Is player dealer? "+(pa.isDealer()));
             System.out.println("Is player big blind? "+(pa.isBigBlind()));
             System.out.println("Is player little blind? "+(pa.isLittleBlind()));
        	
        	System.out.println("Player counter is "+pa.counter);
            System.out.println("Ca's counter is "+ca.counter);
            System.out.println("Ca1's counter is "+ca1.counter);
            System.out.println("Ca2's counter is "+ca2.counter);
           
        if(pa.isBankrupt()){
            System.out.println("*****The computer wins*****");
            System.exit(0);
        }
        else if (ca.isBankrupt()){
            System.out.println("*****The player wins*****");
            System.exit(0);
        }    
            
//        System.out.println("Your current bankRoll is now " +pa.getCurrentBankRoll());
//        System.out.println("Ca's current bankRoll is now " +ca.getCurrentBankRoll());
//        System.out.println("Ca1's current bankRoll is now " +ca1.getCurrentBankRoll());
//        System.out.println("Ca2's current bankRoll is now " +ca2.getCurrentBankRoll());
        
        System.out.println(" ");
        roundNo++;
        System.out.println("Round "+roundNo);
        
        //get player bet input
        System.out.println("*****How much would you like to bet?*****");
        pa.pBet = pa.getBetInput();
        if(pa.pBet > pa.getCurrentBankRoll()){
            System.out.println("You don't have that many credits, please try again!");
            pa.pBet = pa.getBetInput();
        }
        pa.takeFromBankRoll(pa.pBet);
        System.out.println(" ");
        
        //randomly generate computer bet for now
        int caBet = (int) (Math.random()*ca.bankRoll);
        ca.takeFromBankRoll(caBet);
        int ca1Bet = (int) (Math.random()*ca1.bankRoll);
        ca1.takeFromBankRoll(ca1Bet);
        int ca2Bet = (int) (Math.random()*ca2.bankRoll);
        ca2.takeFromBankRoll(ca2Bet);
                
        
        pot=0; //reset value while looping
        pot = pot + pa.pBet + caBet + ca1Bet + ca2Bet;
        System.out.println("You bet "+pa.pBet);
        //System.out.println("Computer bet "+ComputerAgent.cBet);
        System.out.println("CA bet "+caBet+ " and CA1 bet "+ca1Bet+" and CA2 "+ca2Bet);
        System.out.println("Your current pot  is "+pot);
        
                
        //input and scorind
        System.out.println(" ");
        System.out.println("*****Please enter a word*****");
        
        //determine scores
        int caScore = ca.getScore();
        int caScore1 = ca1.getScore();
        int caScore2 = ca2.getScore();
        int pScore = pa.getScore(pa.getWordInput());
        
        System.out.println(" ");
        System.out.println("User's score was "+pa.pScore);
        System.out.println("Ca's word was "+ca.bestWord()+"with a score of "+caScore+".");
        System.out.println("Ca1's word was "+ca1.bestWord()+" with a score of "+caScore1+".");
        System.out.println("Ca2's word was "+ca2.bestWord()+" with a score of "+caScore2+".");
        
        System.out.println(" ");
        
        //determine winner
        
        if((pScore > caScore) &&(pScore > caScore1) &&(pScore>caScore2)){
            System.out.println("*******************************");
            System.out.println("Player wins this round!");
            pa.addToBankRoll(pot);
            System.out.println("Your current bankRoll is now " +pa.getCurrentBankRoll());
            System.out.println("Computer's current bankRoll is now " +ca.getCurrentBankRoll());
            System.out.println("*******************************");
        }
        else if ((caScore > caScore1)&&(caScore > caScore2)){
        	
        	System.out.println("Ca wins this round!");
        	ca.addToBankRoll(pot);
        
        }
        
        else if((caScore1 > caScore)&&(caScore1 > caScore2)){
        	System.out.println("Ca1 wins this round!");
        	ca1.addToBankRoll(pot);
        }
        
        else if((caScore2 > caScore)&&(caScore2 > caScore1)){
        	System.out.println("Ca2 wins this round!");
        	ca2.addToBankRoll(pot);
        
        }
        
        else{
        	System.out.println("IT was a tie *logic will come later*");
        }
        
            System.out.println("Your current bankRoll is now " +pa.getCurrentBankRoll());
            System.out.println("Ca's current bankRoll is now " +ca.getCurrentBankRoll());
            System.out.println("Ca1's current bankRoll is now " +ca1.getCurrentBankRoll());
            System.out.println("Ca2's current bankRoll is now " +ca2.getCurrentBankRoll());
            
            System.out.println("*******************************");
            
            
            pa.incrementCounter();
            ca.incrementCounter();
            ca1.incrementCounter();
            ca2.incrementCounter();
            
        
        }//end of while loop
        

    }
}
